<section class="post-comments">
    {% if site.comment.changyan %}
    <div id="SOHUCS" sid="{{ page.url }}"></div> 
    <script type="text/javascript"> 
    (function(){ 
        var appid = '{{site.comment.changyan.appid}}'; 
        var conf = '{{site.comment.changyan.conf}}'; 
        var width = window.innerWidth || document.documentElement.clientWidth; 
        
        // 防止重复加载：检查是否已有changyan评论实例
        if (window.changyan && window.changyan.api) {
            // 重新配置已存在的changyan实例
            window.changyan.api.config({appid: appid, conf: conf});
            return;
        }
        
        if (width < 1000) {
            var head = document.getElementsByTagName('head')[0]||document.head||document.documentElement;
            // 检查移动端脚本是否已加载
            if (document.getElementById('changyan_mobile_js')) {
                return;
            }
            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.charset = 'utf-8';
            script.id = 'changyan_mobile_js';
            script.src = 'https://cy-cdn.kuaizhan.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf;
            head.appendChild(script);
        } 
        else {
            var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;
            var b=document.createElement("script");
            b.setAttribute("type","text/javascript");
            b.setAttribute("charset","UTF-8");
            b.setAttribute("src",d);
            if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;
                                      if(e==="loaded"||e==="complete"){b.onreadystatechange=null;
                                        a()}}}
                                        else{b.onload=a}}c.appendChild(b)};
                                        loadJs("https://cy-cdn.kuaizhan.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})});
            } 
        }
    )();
    </script>
    {% elsif site.comment.beaudar %}
    <script>
    // 防止重复加载：检查是否已有beaudar评论
    if (!document.querySelector('.beaudar, .utterances')) {
        var script = document.createElement('script');
        script.src = "https://beaudar.lipk.org/client.js";
        script.setAttribute('repo', '{{site.comment.beaudar.repo}}');
        script.setAttribute('branch', '{{site.comment.beaudar.branch}}');
        script.setAttribute('issue-term', '{{site.comment.beaudar.issue-term}}');
        script.setAttribute('theme', '{{site.comment.beaudar.theme}}');
        script.setAttribute('crossorigin', '{{site.comment.beaudar.crossorigin}}');
        script.async = true;
        document.querySelector('.post-comments').appendChild(script);
    }
    </script>
    {% elsif site.comment.livere %}
      <div id="lv-container" data-id="city" data-uid="{{site.comment.livere}}">
      <script type="text/javascript">
         (function(d, s) {
             var j, e = d.getElementsByTagName(s)[0];

             // 防止重复加载：检查LivereTower是否已存在或脚本是否已加载
             if (typeof LivereTower === 'function' || d.querySelector('script[src*="embed.dist.js"]')) { 
                 // 如果LivereTower已存在，重新初始化评论区域
                 if (typeof LivereTower === 'function') {
                     try {
                         LivereTower.init();
                     } catch (e) {
                         console.log('LivereTower重新初始化:', e);
                     }
                 }
                 return; 
             }
             j = d.createElement(s);
             j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
             j.async = true;
             e.parentNode.insertBefore(j, e);
         })(document, 'script');
      </script>
      <noscript>为正常使用来必力评论功能请激活JavaScript</noscript>
      <style>
        .trc_rbox_container{
            display: none !important;
        }
      </style>
      </div>

  {% elsif site.comment.disqus %}
    <div id="disqus_thread"></div>
    <script>
    // 防止重复加载：清除之前的评论
    if (typeof DISQUS !== 'undefined') {
        DISQUS.reset({
            reload: true,
            config: function () {
                this.page.url = "{{ page.url | prepend: site.baseurl | prepend: site.url }}";
                this.page.identifier = "{{ page.url }}";
            }
        });
    } else {
        var disqus_config = function () {
            this.page.url = "{{ page.url | prepend: site.baseurl | prepend: site.url }}";
            this.page.identifier = "{{ page.url }}";
        };
        var disqus_shortname = '{{ site.comment.disqus }}';
        
        (function() { // DON'T EDIT BELOW THIS LINE
            var d = document, s = d.createElement('script');
            s.src = '//' + disqus_shortname + '.disqus.com/embed.js';
            s.setAttribute('data-timestamp', +new Date());
                (d.head || d.body).appendChild(s);
            })();
    }
    </script>
    <noscript>要查看<a href="http://disqus.com/?ref_noscript"> Disqus </a>评论，请启用 JavaScript</noscript>
    
  {% endif %}

</section>
